<!--[if IE 6]>
		<script src="__PUBLIC__/js/DD_belatedPNG_0.0.8a-min.js" type="text/javascript"></script>  
		<script type="text/javascript">
			DD_belatedPNG.fix('.icon');
		</script>
	<![endif]--> 
<style type="text/css">
<!--
.tab{text-align:left;}
.mytips{color:#888888; float:right;padding-top:7px;}
.itips{ background: #FFFBCC;
    border-bottom: 1px solid #D7D7D7;
    padding: 20px 0 }

.tab1,.tab2,.tab3,.tab4{ border-left: 2px solid #E1DFDF;
    color: #524D4D;
    float: left;
    font-size: 18px;
    height: 250px;
    padding: 20px;
    text-align: center;
    width: 140px;}

#bg .icon {
    background: url("__THEME__/images/AddIcons.png") repeat scroll 0 0 transparent;
    height: 81px;
    margin: 30px auto 30px;
    width: 66px;
}
.icon span{
    color: #524D4D;
    font-size: 18px;
    text-align: center;
	}

#bg #upload {
    background-position: -66px 0;
}
#bg #goods {
    background-position: -198px 0;
}

#bg #board {
    background-position: -132px 0;
}

.tab1 {
    border-left-width: 0;
}
#bg a{
 cursor:pointer;color:#524D4D;
 text-decoration:none;
}
#bg a:hover {
    background-color: #E1DFDF;
}

-->
</style>
<Script>
var II=0;
</Script>
<script type=text/javascript>

	function setTab03Syn ( i )
	{
		selectTab03Syn(i);
	}
	
	function selectTab03Syn ( i )
	{
		switch(i){
			case 1:
			document.getElementById("TabTab03Con1").style.display="block";
			document.getElementById("TabTab03Con2").style.display="none";
			document.getElementById("TabTab03Con3").style.display="none";
			document.getElementById("TabTab03Con4").style.display="none";
			document.getElementById("saybox").style.display="block";
			document.getElementById("daohang").style.display="none";
			document.getElementById("talkBox").style.height="270px";
			document.getElementById("talkBox").style.width="706px";
			break;
			case 2:
			document.getElementById("TabTab03Con1").style.display="none";
			document.getElementById("TabTab03Con2").style.display="block";
			document.getElementById("TabTab03Con3").style.display="none";
			document.getElementById("TabTab03Con4").style.display="none";
			document.getElementById("saybox").style.display="block";
			document.getElementById("daohang").style.display="none";
			document.getElementById("talkBox").style.height="270px";
			document.getElementById("talkBox").style.width="706px";
			
			break;
			case 3:
			document.getElementById("TabTab03Con1").style.display="none";
			document.getElementById("TabTab03Con2").style.display="none";
			document.getElementById("TabTab03Con3").style.display="block";
			document.getElementById("TabTab03Con4").style.display="none";
			document.getElementById("saybox").style.display="block";
			document.getElementById("daohang").style.display="none";
			document.getElementById("talkBox").style.height="330px";
			document.getElementById("talkBox").style.width="706px";
			break;
			case 4:
			document.getElementById("TabTab03Con1").style.display="none";
			document.getElementById("TabTab03Con2").style.display="none";
			document.getElementById("TabTab03Con3").style.display="none";
			document.getElementById("TabTab03Con4").style.display="block";
			document.getElementById("saybox").style.display="block";
			document.getElementById("daohang").style.display="none";
			document.getElementById("talkBox").style.height="270px";
			document.getElementById("talkBox").style.width="706px";
			break;
		}
	}
	
window.onerror = ignoreError;
function ignoreError()
{
   return true;
}	
$(function(){
	var cityChosen = getCookie('citychosen');
	if(cityChosen!=null && cityChosen!=''){
		var chosen = $('#bc_id option[value="'+cityChosen+'"]');
		chosen.attr('selected',true);
		//$("#output").removeClass().addClass(cityChosen).html("你上次选择了<br />" + chosen.text());
	}
	$("#bc_id").change(function(){
		var selected = $("#bc_id option:selected");		
		var output = "";
		if(selected.val() != 0){
			setCookie('citychosen',selected.val(),365);
			//output = "你这次选择了<br />" + selected.text();
		}
		//$("#output").removeClass().addClass(selected.val()).html(output);
	});
});
//以下是用来处理Cookies的函数
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function dropCookie(name) {
	createCookie(name,"",-1);
}

</script>

<php>if(!$nobc){</php>

<div style="width:500px;height:200px;">
       <div style="padding-top:70px"><a href="javascript:;" onclick="ui.box.close();setBcTab()"><img src="__THEME__/images/newtuge.jpg" /></a></div>
</div>


        <php>}else{</php>


<div class="tab clear" id="daohang">

	<div id="bg" class="xixi1">
		<a id="font1" class="tab1" onClick="publish_type_box('image',150);setTab03Syn(1);document.getElementById('bg').className='xixi1'"><div id="upload" class="icon"></div><span>本地图片</span></a>
		<a id="font3" class="tab3" onClick="publish_type_box('goods',150);setTab03Syn(3);document.getElementById('bg').className='xixi3'"><div id="goods" class="icon"></div><span>分享宝贝</span></a>
		
	</div>
   
</div>
<div class="tabContent talkBox" id="talkBox">
    <form method="post" action="{:U('weibo/Operate/publish')}" id="miniblog_publish" oncomplete="false">
        <input type="hidden" name="publish_type" value="0">
<div id="taobao_goods_images" style="display: none;">
                <a id="click_url_img" href="#"><img id="goods_img" src=""></a>
            
<div style="position:relative;"><div class="jiage">￥<span id="price"></span></div></div>
<div style="display:none;">自动分类：<span id="fenlei"></span></div>
<div>
 <a id="click_url" href="" title="" target="_blank"></a></div>
                        <input type="hidden" id="cold_goods_form_title" value="">
</div>

<div id="selectfl2" style="display: none;text-align:left;">
<span class="gred" style="font-size:14px;padding-top:5px;">请选择分类标签：</span>

<ul class="nt_list">
<php>
$i=1;
foreach ($label as $l){
	</php>
	<li><input type="text" id="tag_input{$i}" value="{$l['node_name']}" style="display:none;"><a title="添加分类" href="javascript:;" onclick="doUserTag{$i}()">{$l['node_name']}</a><i></i></li>
	<Script Language=Javascript>
	function doUserTag{$i}(){
		var count=$('#tagcount1').html();
		if(count>0){
			ui.error('最多选择1个分类标签');
		}else{
			var tag=$('#tag_input{$i}').val();
			tag = tag.trim();

			if (tag){
	
				var sum_count=$('#tagcount').html();
				var result=0;
				if (sum_count==0){
				}else{
					/*
					if (sum_count==1){
						if (document.getElementById("goodstag[]").value==tag){
							result=1;
						}
					}else{
						for(var i=0;i<document.getElementById("goodstag[]").length;i++){
							if (document.getElementById("goodstag[]").item(i).value==tag){
								result=1;
							}
						}
					}
					*/
				}
				if (result==0){
					var html= '<li class="alltag" id=Lab'+II+'>'+tag+' <span style="cursor:hand" onClick="Javascript:FUN_REMOVE(\''+II+'\');">X</span></li>';
					var input='<input name="goodstag[]" id=Tag'+II+' type="text" value="'+tag+'">';

					$("#tag").append(html);
					$("#tagcount1").html(parseInt(count)+1);
					$('#tag_inputs').append(input);
					$('#tag_input').val('');

					 var count=$('#tagcount').html();
					$("#tagcount").html(parseInt(count)+1);
					
					II++;
				}
			}else{
				ui.error('请选择分类标签或添加时尚元素标签');
			}
		}	
	}
	</Script>
	<php>
	$i++;
}
</php>


</ul>

								
								
								<span style="display:none;" id="tagcount1">0</span>
								<div class="clear" style="padding-top:10px;"> 
					<div style="float:right; display:none;"><a onclick="deleteTag('alltag')" href="javascript:;"><img src="__THEME__/images/close.gif" /></a></div>
					<span class="tagList" id="tag" style="width:80px;">
						</span>
						</div>
	  </div>



<div id="saybox">
<div class="swfbtn">
	
	<div id="publish_type_content_before"></div>
<div id="TabTab03Con1">

	  </div>
<div id="TabTab03Con2" style="display:none"></div>	
<div id="TabTab03Con3" style="display:none;">



<div id="selectfl" style="display: none;" class="floatleft">
<div style="padding-top:2px;"><input type="button" value="重新添加" class="btn_b" onClick="publish_type_box('goods',150);"></div>
</div>
								
								
                    

</div>
<div id="TabTab03Con4" style="display:none;"></div>

</div>

<div class="c" style="height:0px;*height:40px;"></div>
<div class="textareabox margin">
<h2><div class="wordNum">你还可以输入<strong id="strconunt">140</strong>字</div><select name="bc_id" id="bc_id" style="width:122px;">


            <volist name="bcdisplay"  id="bcd">


                <option value="{$bcd.bc_id}" >{$bcd.title}</option> 


            </volist> 

        </select> <input type="text" name="bcTitle"  value="添加新图格" class="text" style="width:120px; color:#888;" onfocus="if(value=='添加新图格') {value=''}" onblur="if (value=='') {value='添加新图格'}"/>

        <input type="button" onclick="createBc()"  class="btn_b" value="创建"/></h2>
        <div class="cntBox">
            <textarea name="content" id="content_publish" cols="" rows="" style="width:98%; height:78px;padding:5px 0;"></textarea>
			<div id="tag_inputs" style="display:none"></div>
            <div class="txtShadow" style="z-index:-1000;display:none"></div>

        </div>
        <div class="funBox">
            <div class="right" style="padding-bottom:5px;">
			 <label>同步到:<input type="checkbox" name="sync[]" value="sina" id="sina_sync" <php>if($login_bind['sina']){</php>checked<php>}</php> onclick="selectSync(this)"></label>
                <img src="__THEME__/images/sina.png" align="absmiddle" />
                <input type="button" onclick="publish_weibo()" disabled="true" class="btn_big_disable hand" value="&nbsp;" id="publish_handle"  />
            </div>
            <div class="left"> <span>添加：</span>
                <a href="javascript:void(0)" target_set="content_publish" onclick="ui.emotions(this)" class="a52"><img class="icon_add_face_d" src="__THEME__/images/zw_img.gif" />表情</a>
                <a href="javascript:void(0)" onclick="publish_type_box('theme')" class="a52"><img class="icon_add_topic_d" src="__THEME__/images/zw_img.gif" />话题</a> 
        
            </div>
			
        </div>
</div>


</div>


<input id="fenlei_input" name="fenlei_input" type="hidden"/></input>
</form>
</div>
<php>}</php>
<script>
    
 $(document).ready(function(){
 		//document.getElementById( "font1").click(); 
        var $content_publish = $("#content_publish");
        var Interval;
        $content_publish.keypress(function(event){
            var key = event.keyCode?event.keyCode:event.which?event.which:event.charCode;
            if (key == 27) {
                clearInterval(Interval);
            }
            checkInputLength(this,140);
        }).blur(function(){
            clearInterval(Interval);
            checkInputLength(this,140);
        }).focus(function(){
            //微博字数监控
            clearInterval(Interval);
            Interval = setInterval(function(){
                checkInputLength('#content_publish',140);
            },300);
        });
        if (!-[1,]) {
            $content_publish.focus().val('{$text}');
        }else{
            $content_publish.select().focus().val('{$text}');
        }
        //微博字数控制
        checkInputLength('#content_publish',140);
	
        shortcut('ctrl+return',	function(){publish_weibo();clearInterval(Interval);},{'target':'miniblog_publish'});

        var url = "{:U('home/User/searchTips')}";
        userAutoTips({id:'content_publish',url: url});
    });

    //发布微博
    function publish_weibo(){
        if( $.trim( $('#content_publish').val() ) == '' ){
            alert('内容不能为空');		
            return false;
        }
                
        if( $.trim( $('#bc_id').val() ) == '' ){
            alert('分类不能为空');		
            return false;
        }
		
		if( $.trim( $('#pickpic').val() ) == '' ){
            alert('你没上传图片 or 分享宝贝 or 发布视频?');		
            return false;
        }
	
                
      
                
        textareaStatus('sending');
        var options = {
            success: function(txt) {
                if(txt){
                    delTypeBox();
                    $("#feed_list").prepend( txt ).slideDown('slow');
                    $('#miniblog_publish').clearForm();
                    weibo.upCount('miniblog');
                    checkInputLength('#content_publish',140);
                    delTypeBox();
                    $('#miniblog_publish').clearForm();
                    ui.box.close();
					//location.reload();
					var url = "{:U('home/User/index')}";
					window.location = url;
					
                }else{
                    alert( '发布失败' );
                }
            }
        };		
        $('#miniblog_publish').ajaxSubmit( options );
        return false;
    }

    function setSearchUser(txt){
        reg = /@[^@\s]{1,20}$/g
        var   patt   =   new   RegExp(reg);
        var result = patt.exec( txt.val() );

        var textArea = document.getElementById('content_publish');
        if(result){
            $(".txtShadow").html( '@' + '<span id="showTips"></span>');
            var p = $("#showTips").offset();
            $('#searchUser').css({top:p.top,left:p.left});
            $('#searchUser').show();
        }else{
            $('#searchUser').hide();
        }
    }

    //检测输入字符数
    function checkInputLength(obj,num){
        var len = getLength($(obj).val(), true);
		var mycontent=$("#pickpic").val();
        var wordNumObj = $('.wordNum');
        if(len==0){
            textareaStatus('off');
            wordNumObj.css('color','').html('你还可以输入<strong id="strconunt">'+ (num-len) + '</strong>字');
        }else if( len > num ){
            wordNumObj.css('color','red').html('已超出<strong id="strconunt">'+ (len-num) +'</strong>字');
            textareaStatus('off');
        }else if( len <= num && mycontent != ''){
            wordNumObj.css('color','').html('你还可以输入<strong id="strconunt">'+ (num-len) + '</strong>字');
            textareaStatus('on');
        }
    }
	
	
	
	

    //发布窗口、按钮状态
    function textareaStatus(type){
        var obj = $('#publish_handle');
        if(type=='on'){
            obj.removeAttr('disabled').attr('class','btn_big hand');
            //}else if( type=='sending'){
            //	obj.attr('disabled','true').attr('class','btn_big_disable hand');
        }else{
            obj.attr('disabled','true').attr('class','btn_big_disable hand');
        }
    }







    //发布类型
    function publish_type_box(type,mg_left){
        var publis_type_html = '';
        var type_num = 0;
        switch(type){
            case 'theme':
                var text = '#请在这里输入自定义话题#';
                var   patt   =   new   RegExp(text,"g");  
                var content_publish = $('#content_publish');
                var result;
						
                if( content_publish.val().search(patt) == '-1' ){
                    content_publish.val( content_publish.val() + text);
                }
			
                var textArea = document.getElementById('content_publish');
			
                result = patt.exec( content_publish.val() );
			
                var end = patt.lastIndex-1 ;
                var start = patt.lastIndex - text.length +1;
			
                if (document.selection) { //IE
                    var rng = textArea.createTextRange();
                    rng.collapse(true);
                    rng.moveEnd("character",end)
                    rng.moveStart("character",start)
                    rng.select();
                }else if (textArea.selectionStart || (textArea.selectionStart == '0')) { // Mozilla/Netscape…
                    textArea.selectionStart = start;
                    textArea.selectionEnd = end;
                }
                textArea.focus();
                checkInputLength('#content_publish',140);
                return ;
                break;
		
            case 'image':
                type_num = 1;
                publish_type_html = '<div class="indeximg"><div class="mytips">仅支持JPG、GIF、PNG图片文件，且文件小于2M</div></div><div id="upload_selectpic"><div class="btn_green2" >'+
								'<form action=\'{:U("weibo/plugins/before_publish")}\' enctype="multipart/form-data" method="post" id="uploadpic">'+
								'<a class="gp_btn_c"><input type="file" hidefoucs="true" name="pic" onchange="weibo.plugin.image.upload(this)"></a><input type="hidden" name="plugin_id" value="1">'+
								'</form></div></div><div class="alC pt10 pb10 f14px" id="upload_loading" style="display:none"><img src="'+ _THEME_+'/images/icon_waiting.gif" width="20" class="alM"> 正在上传中...<br /><a class="btn_w mt10" href="javascript:void(0)" onclick="$(\'div .talkPop\').remove();stopAjax();">取消上传</a></div>';
                break;
					
			case 'goods':
				type_num = 5;
				publish_type_html = '<div class="indeximg"><div class="mytips">暂支持淘宝和拍拍，右侧输入链接</div></div><div class="mymargin"><input name="publish_type_data" type="text" style="padding:4px 0;width: 235px" class="text mr5" value="" /><input type="button" class="btn_b" onclick="weibo.plugin.goods.add_goods()" value="添加"></div>';
				break;
		
        }

        $('input[name="publish_type"]').val(type_num);

       
	   	var html = '<div class="talkPop notop">'
			 + '<div id="publish_type_content">'+publish_type_html+'</div>'
			 + '</div>';
	   
        $('div.talkPop').remove();
        $("#publish_type_content_before").after( html );
    }



String.prototype.trim = function()
{
    // 用正则表达式将前后空格
    // 用空字符串替代。
    return this.replace(/(^\s*)|(\s*$)/g, "");
}


function removeHTMLTag(str) {
            str = str.replace(/(^|:\/\/)(\w+\.)?(\w+\.\w+)(?=(\/|$))/,''); //去除HTML tag
            //str = str.replace(/[ | ]*n/g,'n'); //去除行尾空白
            //str = str.replace(/n[s| | ]*r/g,'n'); //去除多余空行
            str=str.replace(/&nbsp;/ig,'');//去掉&nbsp;
            return str;
    }


function doUserTag(){
    var count=$('#tagcount').html();
	if(count>4){
		ui.error('只能输入5个时尚元素标签');
	}else{
		var tag=$('#tag_input').val();
		tag = tag.trim();
		tag = removeHTMLTag(tag);
		if (tag){

			var arr=tag.split(",");
			for (var i=0;i<=arr.length-1;i++){
				var tag=arr[i];
				var tag=tag.trim();
				var tag = removeHTMLTag(tag);

				var result=0;
				if (count==0){
				}else{
					/*
					if (count==1){
						if (document.getElementById("goodstag[]").value==tag){
							result=1;
						}
					}else{
						for(var i=0;i<document.getElementById("goodstag[]").length;i++){
							if (document.getElementById("goodstag[]").item(i).value==tag){
								result=1;
							}
						}
					}
					*/
				}
				if (result==0){

					var html= '<li class=alltag id=Lab'+II+'>'+tag+' <span style="cursor:hand" onClick="Javascript:Fun_Remove(\''+II+'\');">X</span></li>';
					var input='<input name=goodstag[] id=Tag'+II+' type="text" value="'+tag+'">';

					//var html= '<li class="alltag">'+tag+'</li>';
					//var input='<input id="goodstag[]" name="goodstag[]" type="text" value="'+tag+'">';
					$("#tag").append(html);
					$("#tagcount").html(parseInt(count)+1);
					$('#tag_inputs').append(input);
					//$('#content_publish').append('#'+tag+'#');
					$('#tag_input').val('');
					
					II++;

				}
			}
		}else{
			ui.error('请选择分类标签或添加时尚元素标签');
		}
	}
}



function Fun_Remove(I){
	document.getElementById("Lab"+I).style.display='none';
	document.getElementById("Tag"+I).value='';

	var count=$('#tagcount').html();
	var count=parseInt(count);
	if (count>0)
		$('#tagcount').html(count-1);
}
function FUN_REMOVE(I){
	document.getElementById("Lab"+I).style.display='none';
	document.getElementById("Tag"+I).value='';

	var count=$('#tagcount').html();
	var count=parseInt(count);
	if (count>0)
		$('#tagcount').html(count-1);
	
	var count=$('#tagcount1').html();
	var count=parseInt(count);
	if (count>0)
		$('#tagcount1').html(count-1);
}

function deleteTag(o){
	$('.'+o).remove();
	$('.'+o).hide();
	var content=$('#content_publish').html();
	$('#content_publish').html(content.replace('#'+o+'#',''));
	$('#tag_inputs').html(content.replace('#'+o+'#',''));
	var count=0;
	$("#tagcount").html(0);
	$("#tagcount1").html(0);
}

function close_taobao(){
   $('#taobao').hide();
   $('.talkPop').remove();
}

function createBc(title){
	var title = $("input[name='bcTitle']").val();
         
         if(title == ''){
		ui.error('请输入图格标题！');
		return false;
	}else if(title.length>20){
		ui.error('图格标题不能超过20个汉字');
		return false; 
	}
 	var uid = '{$mid}';
		$.post(U('weibo/Bc/setBc'),{uid:uid,title:title},function(gid){
			if(gid != 0){
                           
				// var url =   U('home/User/index'); 
                                //location.href=url;
				//ui.success('新建成功');
                                
                                var mySelect = document.getElementById("bc_id");  
                                //通过new Option(value,text)函数
                                var opp = new Option(title,gid); 
                                    opp.name = "option1"; 
                                    opp.selected = "ture";
                                    //将option添加到select标签里面 
                                    mySelect.add(opp); 
                                
                             
                            // $("#bc_id").html ('<option value="'+gid+'" selected>'+title+'</option>');    
                                
				//ui.box.close();
			}else{
				ui.error('此图格已存在');
			}
		});		
	 
}


</script> 